package com.jiaquyun.jcyx.jetpack.mode

import android.app.Application
import androidx.lifecycle.MutableLiveData
import com.jiaquyun.jcyx.app.JCApplication
import com.jiaquyun.jcyx.jetpack.api.GoodsRepository
import com.jiaquyun.jcyx.jetpack.api.IndexRepository
import com.jiaquyun.jcyx.entity.GoodsListResponse
import com.jiaquyun.jcyx.entity.GoodsRequest
import com.jiaquyun.jcyx.entity.HomeResponse
import com.jiaquyun.jcyx.base.BaseViewModel
import com.module.lemlin.http.HttpResponseBody
import com.module.lemlin.http.HttpResponseData
import com.module.lemlin.http.SubscribeViewModel

class HomeViewModel(application: Application) : BaseViewModel(application) {

    private val mIndexRepository = IndexRepository()
    private val mGoodsRepository = GoodsRepository()

    val homeLiveData = MutableLiveData<HttpResponseBody<HomeResponse>>()
    val goodsListLiveData = MutableLiveData<HttpResponseBody<GoodsListResponse>>()
    val baseLiveData = MutableLiveData<HttpResponseBody<HttpResponseData>>()

    fun index() {
        setRxLifeScope(SubscribeViewModel(homeLiveData)) {
            mIndexRepository.index()
        }
    }

    fun indexAndGoodsList() {
        val goodsRequest = GoodsRequest(shop_id = "${JCApplication.userShops?.id?:"55"}", active_type = 1, rows = 4)
        setRxLifeScope(SubscribeViewModel(homeLiveData)) {
            mIndexRepository.indexAndGoodsList(goodsRequest)
        }
    }

    fun goodsList() {
        val goodsRequest = GoodsRequest(shop_id = "${JCApplication.userShops?.id?:"55"}", active_type = 1, rows = 4)
        setRxLifeScope(SubscribeViewModel(goodsListLiveData)) {
            mGoodsRepository.goodsList(goodsRequest)
        }
    }
}